from fastapi import APIRouter, Form, UploadFile, File,Request
from pydantic import BaseModel
from datetime import date
from typing import List
import uvicorn

sunInfo = APIRouter()


@sunInfo.post("/regin",summary="注册")
async def regin(username: str = Form(), password: str = Form()):
    return {"username": username, "password": password}


@sunInfo.post("/file",summary="上传图片")
async def get_file(file: UploadFile = File(...)):
    contents = await file.read()
    return {"file": file}

@sunInfo.post("/files",summary="上传多张图片")
async def get_files(files: List[UploadFile] = File()):
    return {"file": files.filename}

@sunInfo.get("/itmes",summary="获取信息")
async def get_itmes(req: Request):
    return {
        "请求URL：": req.url,
        "请求IP：": req.client.host,
        "请求宿主：": req.headers.get("user-agent"),
        "cookies：": req.cookies
    }